package com.wl.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.haoyuban111.mubanapplication.R
import com.example.haoyuban111.mubanapplication.help_class.ContextHelper
import com.example.haoyuban111.mubanapplication.help_class.DataHelper
import com.example.haoyuban111.mubanapplication.ui.activity.ActivityFirst
import com.example.haoyuban111.mubanapplication.ui.fragment.FragmentBase
import com.example.haoyuban111.mubanapplication.ui.view.DividerItemDecoration
import com.wl.adapter.AdapterPopularLocationKotlin

class FragmentRecyclerSecondKotlin : FragmentBase() {

    private var recyclerView: RecyclerView? = null
    private val MARGIN = 20

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater!!.inflate(R.layout.fragment_recycler_second, container, false)
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView() {
        val v = view

        recyclerView = v!!.findViewById(R.id.recyclerView) as RecyclerView
        val layoutManager = GridLayoutManager(ContextHelper.getApplicationContext(), 2)
        val decoration = DividerItemDecoration(ContextHelper.getApplicationContext(), R.drawable.divider, R.color.transparent)
        decoration.setSize(MARGIN)
        decoration.setType(DividerItemDecoration.BORDER)
        recyclerView!!.addItemDecoration(decoration)
        recyclerView!!.layoutManager = layoutManager
        val mAdapter = AdapterPopularLocationKotlin(mContext = ContextHelper.getApplicationContext())
        mAdapter.setData(DataHelper.getSecondModelsKotlin())
        recyclerView!!.adapter = mAdapter
//        mAdapter.setOnItemClickListener { pos:Int}

    }

    fun startActivity(){
        val intent = Intent(activity,ActivityFirst::class.java)
        startActivity(intent)
    }
}
